----------------------------------Spell Variables--------------------------------------
SPELL.m_iSpellID = 13130 -- Whatever value you want as long as it doesn't override any other spells' IDs.
SPELL.m_iRange = 240
SPELL.m_sName = "Blademaster Auto Attack"
SPELL.m_sToolTip =	[[Swing your weapon
					at the target.]]
SPELL.m_sIcon = "devin/blackbetty/spells/blademaster/auto_1.png"
SPELL.m_iCoolDown = 1.5
SPELL.m_iManaCost = 0
SPELL.m_bRequiresTarget = true
SPELL.m_iSpellType = SPELLTYPE_MAA_AUTOATTACK
SPELL.m_bRecastWhileCasting = false

---------------------------------------------------------------------------------------

function SPELL:Cast( pl, target )
	local weapon = pl:GetWeapon("weapon_all")
	local range = self.m_iRange
		
	if(target && target:IsValid() && target != pl && target:Health() > 0) then
		ParticleEffectAttach( "slam", PATTACH_POINT_FOLLOW, pl, pl:LookupAttachment("anim_attachment_RH"))
		pl:DoAnimationEvent(ACT_HL2MP_GESTURE_RANGE_ATTACK_MELEE2)
		hitdelay = 0.3
		pl:EmitSound("devin/blackbetty/weapons/swing/2h_"..math.random(1,3)..".wav", 100, 100+math.random(-10,10))
		if(range >= (pl:GetPos() - target:GetPos()):Length())then
			timer.Simple(hitdelay, 
			function()
				print("a")
				if(target and target:IsValid() and weapon and weapon:IsValid())then
					target:EmitSound("devin/blackbetty/weapons/heroic_strike/hit_"..math.random(1,3)..".wav", 100, 100+math.random(-10,10))
					target:EmitSound("devin/blackbetty/weapons/RendTarget.wav", 100, 100+math.random(-10,10))
					ParticleEffect( "player_blood", target:GetPos() + Vector(0, 0, 46) + (target:GetAngles():Forward()*6), Angle(0,0,0), pl )
					local dmginfo = DamageInfo()
					dmginfo:SetDamage( math.random(weapon.MinWeaponDamage, weapon.MaxWeaponDamage) ) 
					dmginfo:SetDamageType( DMG_GENERIC )
					dmginfo:SetAttacker( pl )
					target:TakeDamageInfo( dmginfo )
					UpdatePlayerResource(pl, 7, true)
				end
			end)
		end
	end
end




